package com.fnst.caesar.servlet;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.ibatis.io.*;
import org.apache.ibatis.session.*;

import com.fnst.caesar.bean.*;
import com.fnst.caesar.util.*;

/**
 * Servlet implementation class ClassInfo_Servlet
 */
public class ClassInfo_Servlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ClassInfo_Servlet()
	{
		super();
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		doPost(request, response);
	}
	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
		String queryType = request.getParameter("queryType");
		String keyWord = request.getParameter("keyWord");
		
		SqlSessionFactory ssf = SqlFactoryUtil.getSqlSessionFactory(request);
		SqlSession sqlSession = ssf.openSession();
		
		List queryResult = new ArrayList();
		QueryClassTeach_sqlBean sqlBean = new QueryClassTeach_sqlBean();
		
		if(queryType == null)
		{
			queryResult = sqlSession.selectList("com.fnst.caesar.mapper.selectClassTeachAll", "nothing");
			sqlSession.close();
			request.setAttribute("queryResult", queryResult);
			request.getRequestDispatcher("/WEB-INF/WEB/Class_Info.jsp").forward(request, response);		
		}
		else
		{
			int flag = Integer.parseInt(queryType);
			switch (flag)
			{
			case 1:
				sqlBean.setClass_id(keyWord);
				break;
			case 2:
				sqlBean.setClass_name(keyWord);
				break;
			case 3:
				sqlBean.setClass_teachNo(keyWord);
				break;
			case 4:
				sqlBean.setClass_teacher(keyWord);
				break;
			}
			queryResult = sqlSession.selectList("com.fnst.caesar.mapper.selectClassTeachByKeyword", sqlBean);
			sqlSession.close();
			request.setAttribute("queryResult", queryResult);
			request.getRequestDispatcher("/WEB-INF/WEB/Class_Info.jsp").forward(request, response);
		}
	}
	
}
